<?php
include_once LIB_PATH . DS . 'getFilePaths.php';
use OSS\Core\OssException;
use OSS\OssClient;

function deploy($bucket, $path)
{
    stdout('在' . $bucket . '部署' . $path . '的静态内容');
    $localPaths = getFilePaths($path);
    foreach ($localPaths as $value) {
        ossUpload($bucket, trim(str_replace($path . DS, ' ', $value)), trim($value));
    }
}

function ossUpload($bucket, $object, $filePath)
{
    try {
        $ossClient = new OssClient(ossAccessKeyId, ossAccessKeySecret, ossEndpoint);
        $ossClient->uploadFile($bucket, $object, $filePath);
    } catch (OssException $e) {
        printf(__FUNCTION__ . ": FAILED\n");
        printf($e->getMessage() . "\n");
        return;
    }
    print(__FUNCTION__ . ': ' . $object . ": OK" . "\n");
}
